<template>
  <div class="table-page-search-wrapper">
    <a-card>
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="6" :sm="12">
            <a-form-item label="国内生课程代码">
              <a-input v-model="queryParam.gnskcdm"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
            <a-form-item label="国际生课程代码">
              <a-input v-model="queryParam.gjskcdm"/>
            </a-form-item>
          </a-col>
          <a-col :md="16" :sm="20">
            <span class="table-page-search-submitButtons">
              <a-button type="primary" @click="toAdd">添加</a-button>
            <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </a-card>

    <a-card :bordered="false" style="margin-top: 10px">
      <s-table
        v-if="initDone"
        ref="table"
        size="default"
        rowKey="id"
        :columns="columns"
        :data="loadData"
        :alert="{ show: true }"
        :pageSize="parameter.pageSize"
        :pageNum="parameter.pageNum"
        :scroll="{ x: 1600 }"
      >
         <span slot="serial" slot-scope="text, record, index">
            {{ index + 1 }}
          </span>
        <template slot="operation" slot-scope="a,b">
          <a @click="showDetail(b)">查看明细</a>
          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">
              更多
              <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="toEdit(b)">修改</a>
              </a-menu-item>
              <a-menu-item>
                <a @click="deleteCourse(b)">删除</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </template>
      </s-table>
    </a-card>

    <info-detail :visible="detailVisible" @cancel="detailVisible = false" :confirmLoading="confirmLoading"
                 :info="info"/>

  </div>
</template>

<script>
  import {STable} from '~'
  import {mapState} from 'vuex'
  import infoDetail from './detail'
  import searchMixin from '@/utils/searchRemain'

  export default {
    mixins: [searchMixin],
    data() {
      return {
        advanced: true,
        queryParam: {},
        columns: [
          {
            title: '序号',
            scopedSlots: {customRender: 'serial'}
          },
          {
            title: '国内生课程代码',
            dataIndex: 'gnskcdm'
          },
          {
            title: '国内生课程名',
            dataIndex: 'gnskcmc'
          },
          {
            title: '国际生课程代码',
            dataIndex: 'gjskcdm'
          },
          {
            title: '国际生课程名',
            dataIndex: 'gjskcmc'
          },
          {
            title: '培养层次',
            dataIndex: 'pyccmc'
          },
          {
            title: '培养模式',
            dataIndex: 'pymsmc'
          },
          {
            title: '学分',
            dataIndex: 'xf'
          },
          {
            title: '操作',
            width: '160px',
            dataIndex: 'operation',
            fixed: 'right',
            scopedSlots: {customRender: 'operation'}
          }
        ],
        parameter: {
          pageNo: 1,
          pageSize: 10
        },
        loadData: parameter => {
          this.parameter = parameter
          parameter.pageNum = parameter.pageNo
          let params = Object.assign(this.queryParam, parameter)
          return this.$api.cultivate.ggkcList(params).then(res => {
            return {
              data: res.data.rows,
              pageNo: parameter.pageNum,
              pageSize: parameter.pageSize,
              totalPage: Math.ceil(res.data.total / parameter.pageSize),
              totalCount: res.data.total
            }
          })
        },
        selectMenu: {
          yx: []
        },
        detailVisible: false,
        confirmLoading: false,
        info: {},
        initDone: false
      }
    },
    components: {STable, infoDetail},
    computed: {
      ...mapState({
        TYPE0338: state => state.app['TYPE0338'] // 课程状态
      })
    },
    created() {
      this.$store.dispatch('app/setDictionary', 'TYPE0338')
    },
    methods: {
      filterOption(value, op) {
        return op.componentOptions.children[0].text.indexOf(value) !== -1
      },
      initSelectMenu() {
        let allRequest = [
          this.$api.base.collegeAll()
        ]
        Promise.all(allRequest).then(res => {
          this.selectMenu = {
            yx: res[0].data
          }
          if (this.selectMenu.yx && this.selectMenu.yx.length == 1) {
            this.$set(this.queryParam, 'kcssyxm', this.selectMenu.yx[0].dwh)
          }
          this.initDone = true
        })
      },
      deleteCourse(c) {
        this.$confirm({
          title: '确定删除所选信息?',
          content: '当您点击确定按钮后，此信息将会被彻底删除',
          centered: true,
          onOk: () => {
            this.$api.cultivate.ggkcDelete(c.id).then(() => {
              this.$message.success('删除成功')
              this.selectedRowKeys = []
              this.selectedRows = []
              this.$refs.table.refresh(false)
              this.$refs.table.clearSelected()
            })
          },
          onCancel: () => {
          }
        })
      },
      showDetail(course) {
        this.confirmLoading = true
        this.info = course
        this.detailVisible = true
      },
      toAdd() {
        this.$router.push('/cultivate/ggkc/add')
      },
      toEdit(course) {
        this.$router.push(`/cultivate/ggkc/add?id=${course.id}`)
      },
      filterOption(value, op) {
        return op.componentOptions.children[0].text.indexOf(value) !== -1
      },
    }
  }
</script>

<style>

</style>
